<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
  <title><spring:message code="cc.warning.title" /></title>
  <meta name="decorator" content="list"/>
</head>
<body title="<spring:message code="cc.warning.title" />">
<grid:grid id="ccWarningGridId" url="${adminPath}/cc/warning/warningList" multiselect="false" datatype="local" beforeInit="true" afterInit="true" loadComplete="true" sortname="collectTime" sortorder="desc">
    <grid:column label="sys.common.opt"  name="opt" formatter="button" width="130" sortable="false"/>
    <grid:button title="装车单明细"  groupname="opt" function="rowDialogCommit" winheight="550px" outclass="btn-primary" url="${adminPath}/cc/zcd/mx?zhuangcdNo=\"+row.zhuangcdNo+\"" />

    <%-- 拥有管理员权限的用户，才可以修改温度，其他用户只能够查询 --%>
    <shiro:hasRole name="admin">
        <grid:button title="修改"  groupname="opt" function="rowDialogCommit" winwidth="800px" winheight="400px" outclass="btn-warning" url="${adminPath}/cc/warning/updateEdit?deviceId=\"+row.deviceId+\"&sn=\"+row.sn+\"&collectTime=\"+row.collectTime+\"&temperature=\"+row.temperature+\"&wendMin=\"+row.wendMin+\"&wendMax=\"+row.wendMax+\"" />
    </shiro:hasRole>

    <grid:column label="cc.device.id" name="sbNo" query="true" condition="like"/>
    <grid:column label="cc.device.sn" name="sn" hidden="true"/>
    <grid:column label="cc.zcdHz.zhuangcdNo" name="mxZhuangcdNo" query="true" condition="like"/>
    <grid:column label="cc.humiture.collectTime" name="collectTime" query="true" queryMode="date" condition="between"/>
    <grid:column label="cc.humiture.temperature" name="temperature" />
    <grid:column label="cc.device.highT" name="wendMin" />
    <grid:column label="cc.device.lowT" name="wendMax" />
    <grid:column label="cc.humiture.electric" name="electric" />
    <grid:column label="cc.cangku" name="cangku"/>

	<grid:toolbar function="search"/>
	<grid:toolbar function="reset"/>
</grid:grid>
<script type="text/javascript">
    function beforeInit() {
        var today = new Date();
        $('#collectTime_date').find("input").each(function(){
            $(this).val(today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate());
        });
    }

    function afterInit() {
        var queryParams = {};
        var queryFields=$('#queryFields').val();
        queryParams['queryFields'] = queryFields;
        //普通的查询
        $('#ccWarningGridIdGridQuery').find(":input").each(function() {
            var val = $(this).val();
            if (queryParams[$(this).attr('name')]) {
                val = queryParams[$(this).attr('name')] + "," + $(this).val();
            }
            queryParams[$(this).attr('name')] = val;
        });

        // 普通的查询
        $('#ccWarningGridIdGridQuery').find(":input").each(function() {
            var condition = $(this).attr('condition');
            if (!condition) {
                condition = "";
            }
            var key = "query." + $(this).attr('name') + "||" + condition;
            queryParams[key] = queryParams[$(this).attr('name')];
        });

        $("#ccWarningGridIdGrid").jqGrid('setGridParam',{
            postData:queryParams, //发送数据
            datatype:'json',
            mtype:'get',
            url:'${adminPath}/cc/warning/warningList?gridtype=jqgrid',
            prmNames:{
                //请求参数格式预处理
                page:"page.pn",
                rows:"page.size",
                sort:"sort",
                order: "order"
            }
        }).trigger('reloadGrid');
    }

    function complete() {
        var ids = $("#ccWarningGridIdGrid").jqGrid("getDataIDs");
        var rowDatas = $("#ccWarningGridIdGrid").jqGrid("getRowData");
        var rowData;
        $("#ccWarningGridIdGrid").css("color", "#424242");
        for (var i = 0; i < rowDatas.length; i++) {
            rowData= rowDatas[i];
            if (parseFloat(rowData.temperature) >= (parseFloat(rowData.wendMax) - 0.5)) {
                $("#ccWarningGridIdGrid").find($("#"+ids[i])).css("background-color", "#F4606C");
            }
            else {
                $("#ccWarningGridIdGrid").find($("#"+ids[i])).css("background-color", "#A0EEE1");
            }
        }
    }
</script>
</body>
</html>